package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.SystemDictionary;
import cn.wolfcode.crm.service.ISystemDictionaryService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("systemDictionary")
public class SystemDictionaryController {

    @Autowired
    private ISystemDictionaryService systemDictionaryService;

    @RequestMapping("view")
    public String view(){
        return "systemDictionary";
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public Object selectAll(){
        return systemDictionaryService.list();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(SystemDictionary systemDictionary){
        JSONResult result = new JSONResult();
        try {
            systemDictionaryService.saveOrUpdate(systemDictionary);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.remark("保存失败");
        }
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id){
        JSONResult result = new JSONResult();
        if(id != null){
            try {
                systemDictionaryService.delete(id);
                return result;
            } catch (Exception e) {
                e.printStackTrace();
                return result.remark("保存失败");
            }
        }

        return null;
    }

}
